package org.pms.servlet;

import org.pms.dao.ProductDao;
import org.pms.dao.ProductTypeDao;
import org.pms.dao.impl.ProductDaoImpl;
import org.pms.dao.impl.ProductTypeDaoImpl;
import org.pms.entity.Product;
import org.pms.entity.ProductType;
import org.pms.vo.ResponseData;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.Date;
import java.util.List;

/**
 * 查询商品类型，回显在页面中的查询条件
 *
 * @author zqx
 * @date 2022-12-02
 */
@WebServlet("/admin/AddProductServlet")
public class AddProductServlet extends BaseServlet {
    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {


        String productId = req.getParameter("productId");
        String productName = req.getParameter("productName");
        String productType = req.getParameter("productType");
        String productPrice = req.getParameter("productPrice");
        String productStatus = req.getParameter("productStatus");
        String productDesc = req.getParameter("productDesc");



        // 实例化商品接口对象
        ProductDao productDao = new ProductDaoImpl();

        Product p = new Product();
        p.setProductId(productId);
        p.setProductName(productName);
        p.setProductCount(1000);
        p.setProductImage("computer.jpg");
        p.setProductPrice(Double.parseDouble(productPrice));
        p.setProductStatus(Integer.parseInt(productStatus));
        p.setProductDesc(productDesc);
        p.setProductSale(100);
        p.setProductType(productType);
        p.setProductDate(new Date());

        int r = productDao.insert(p);

        // 封装响应的数据
        ResponseData responseData = successJson(p);

        // 打印输出到客户端浏览器
        print(resp,responseData);
    }
}
